package com.kly.sc.api.application.service.demo;

import java.util.List;

public class ChatSum {


    /**
     * 总共发送的消息跳数
     */
    private Integer totalChatCount;

    private boolean hasChatBefore = false;


    private Integer iceStageCount;
    private Integer validStageCount;
    private Integer deepStageCount;


    private boolean reachIceLimit = false;

    private boolean reachValidLimit = false;

    private boolean reachDeepLimit = false;

    private boolean reachMaxmumLimit = false;

    private Integer sendCount = 0;

    private int remailCount = 0;

    private ChatDataDto matchDto;


    public ChatSum(List<ChatDataDto> chatDataDtoList, String toUserCode) {

        chatDataDtoList.forEach(chatDataDto -> {
            if (chatDataDto.getChatStage() == 1) {
                iceStageCount++;
            } else if (chatDataDto.getChatStage() == 2) {
                validStageCount++;
            } else if (chatDataDto.getChatStage() == 3) {
                deepStageCount++;
            }

            if (chatDataDto.getToUsrCode() == toUserCode) {
                sendCount = chatDataDto.getChatAccount();
                hasChatBefore = true;
                matchDto = chatDataDto;
                if (sendCount >= 100) {
                    reachMaxmumLimit = true;
                }
            }
        });

        if (iceStageCount >= 5) {
            reachIceLimit = true;
        }
        if (validStageCount >= 3) {
            reachValidLimit = true;
        }

        if (deepStageCount >= 1) {
            reachDeepLimit = true;
        }
    }


    public int getRemailCount() {
        if (hasChatBefore) {
            if (matchDto.getChatStage().equals(0)) {
                if(reachIceLimit){
                    return 1-sendCount;
                }

                if (reachValidLimit) {
                    return 5 - sendCount;
                }

                if (reachDeepLimit) {
                    return 30 - sendCount;
                }

                return 100 - sendCount;
            }
            else if (matchDto.getChatStage().equals(1)) {
                if (reachValidLimit) {
                    return 5 - sendCount;
                }

                if (reachDeepLimit) {
                    return 30 - sendCount;
                }

                return 100 - sendCount;
            } else if (matchDto.getChatStage().equals(2)) {
                if (reachDeepLimit) {
                    return 30 - sendCount;
                }

                return 100 - sendCount;
            } else if (matchDto.getChatStage().equals(3)) {
                return 100 - sendCount;
            }
        } else {
            if (reachIceLimit) {
                return 1-sendCount;
            }

            if (reachValidLimit) {
                return 5 - sendCount;
            }

            if (reachDeepLimit) {
                return 30 - sendCount;
            }

            return 100 - sendCount;
        }


        return remailCount;
    }

    public ChatDataDto getMatchDto() {
        return matchDto;
    }

    public ChatSum setMatchDto(ChatDataDto matchDto) {
        this.matchDto = matchDto;
        return this;
    }

    public ChatSum setRemailCount(int remailCount) {
        this.remailCount = remailCount;
        return this;
    }

    public boolean isReachMaxmumLimit() {
        return reachMaxmumLimit;
    }

    public ChatSum setReachMaxmumLimit(boolean reachMaxmumLimit) {
        this.reachMaxmumLimit = reachMaxmumLimit;
        return this;
    }

    public Integer getSendCount() {
        return sendCount;
    }

    public ChatSum setSendCount(Integer sendCount) {
        this.sendCount = sendCount;
        return this;
    }

    public boolean isHasChatBefore() {
        return hasChatBefore;
    }

    public ChatSum setHasChatBefore(boolean hasChatBefore) {
        this.hasChatBefore = hasChatBefore;
        return this;
    }

    public boolean isReachIceLimit() {
        return reachIceLimit;
    }

    public ChatSum setReachIceLimit(boolean reachIceLimit) {
        this.reachIceLimit = reachIceLimit;
        return this;
    }

    public boolean isReachValidLimit() {
        return reachValidLimit;
    }

    public ChatSum setReachValidLimit(boolean reachValidLimit) {
        this.reachValidLimit = reachValidLimit;
        return this;
    }

    public boolean isReachDeepLimit() {
        return reachDeepLimit;
    }

    public ChatSum setReachDeepLimit(boolean reachDeepLimit) {
        this.reachDeepLimit = reachDeepLimit;
        return this;
    }

    public Integer getTotalChatCount() {
        return totalChatCount;
    }

    public ChatSum setTotalChatCount(Integer totalChatCount) {
        this.totalChatCount = totalChatCount;
        return this;
    }

    public Integer getIceStageCount() {
        return iceStageCount;
    }

    public ChatSum setIceStageCount(Integer iceStageCount) {
        this.iceStageCount = iceStageCount;
        return this;
    }

    public Integer getValidStageCount() {
        return validStageCount;
    }

    public ChatSum setValidStageCount(Integer validStageCount) {
        this.validStageCount = validStageCount;
        return this;
    }

    public Integer getDeepStageCount() {
        return deepStageCount;
    }

    public ChatSum setDeepStageCount(Integer deepStageCount) {
        this.deepStageCount = deepStageCount;
        return this;
    }
}
